<?php date_default_timezone_set("Asia/Bangkok"); ?>
<?php $all_session = $this->session->all_userdata(); ?>
<!DOCTYPE html>
<!-- saved from url=(0056)http://startbootstrap.com/templates/simple-sidebar.html# -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Panel</title>
<?php $this->load->view('panel_head');?>


</head>

<body onload="startTime()">

<?php $this->load->view('panel_header');?>
<div style="height:46px;"></div>
<div id="wrapper"> 
  
  <!-- Sidebar -->
  <div id="sidebar-wrapper">
    <?php $this->load->view('panel_sidebar');?>
  </div>
  
  <!-- Page content -->
  <div id="page-content-wrapper">
    <div class="content-header">
      <h1><span class="glyphicon glyphicon-user"></span>&nbsp;Members</h1>



    </div>
    <!-- Keep all page content within the page-content inset div! -->
    
    <div class="page-content inset">
      <div class="row" style="margin-bottom:1em;">
        <div class="col-md-12" >
          <div style="float:left"> <a href="<?php echo base_url();?>index.php/pmember/register">
            <button type="button" class="btn btn-success"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp;Add New Member</button>
            </a> </div>
          <span style="float:right">
          <?php echo form_open('pmember/search');?>
          <input type="text" class="form-control" placeholder="  Search users..." name="search">
          <?php echo form_close();?>
          </span>
          <div style="float:right"></div>
        </div>
        <!-- <div class="col-md-12"> --> 
        
      </div>
      
      <!-- <div class="row"> -->
      
      <div class="row">
        <div class="col-md-12">
          <div style="float:left"> <?php if($this->uri->segment(2) == 'search') { echo "All (".$all.")"; } else {?> All (<?php echo $this->db->count_all('member'); ?>) <?php } ?>
           | Administrator (<?php echo $admin; ?>) |  Modarator (<?php echo $mod; ?>) |  Member (<?php echo $mem; ?>) | Banned (<?php echo $ban;?>)</div>
          <div style="float:right"> <?php echo $total_rows ?> items </div>
        </div>
        <!-- <div class="col-md-12"> --> 
      </div>
      <!-- <div class"row"> -->
      
      <div>
      
       <div class="pagination" style="float:left; margin-top:1em; padding:0;">
        <?php 	echo $this->pagination->create_links(); ?>
        
   
        </div><!-- pagination -->
   
  
   
        <table class="table table-bordered table-hover" style="margin-top:1em; background-color:#fff;">
          
          <tr class="info" align="center">
            <td width="22%" align="left" ><strong>Username</strong></td>
            <td width="32%"><strong>Name</strong></td>
            <td width="20%"><strong>E-mail</strong></td>
            <td width="11%"><strong>Role</strong></td>
            <td width="14%"><strong>Manage</strong></td>
          </tr>
          <?php $i=0; ?>
          <?php foreach($member as $member) { ?>
          
          
          <tr>
            <td><a href="<?php echo base_url();?>index.php/pmember/profile/<?php echo $member['mem_id'];?>">
            <?php if(@$member['mem_image'] == '') { ?>
            <img data-src="holder.js/35x35">
            <?php } else { ?>
            <img src="<?php echo base_url();?>uploads/<?php echo @$member['mem_image'];?>" height="35px;"/>
            <?php } ?>
            &nbsp; <?php echo $member['mem_name']; ?></a></td>
            <td><?php echo $member['mem_fname']; ?> <?php echo $member['mem_lname']; ?></td>
            <td><?php echo $member['mem_mail']; ?></td>
            <td>
			<?php if($member['mem_type'] == 0){ echo "Member"; } else if ($member['mem_type'] == 1) { echo "Moderator"; } else if($member['mem_type']== 2) { echo "Administrator"; } else if($member['mem_type'] == 3) { echo "Banned"; }?>
            </br>
            <?php 
				date_default_timezone_set("Asia/Bangkok");
				$now = date("Y-m-d H:i");

				$exp = (strtotime($member['grant_end']) - strtotime($now))/  ( 60 * 60 );
			?>
            <?php if($exp > 0) { ?>
				      <?php
                        $month_arr = array(
                            '00' => "-",
                            '01' => "January",
                            '02' => "February",
                            '03' => "March",
                            '04' => "April",
                            '05' => "May",
                            '06' => "June",
                            '07' => "July",
                            '08' => "August",
                            '09' => "September",
                            '10' => "October",
                            '11' => "November",
                            '12' => "December"
                        );
                    ?>
                
                    <?php @$around_date = split('-',@$member['grant_end']);
					
					$time = explode(" ", $around_date[2]);
				
						
					?>
           		<font color="orange">Until : <?php echo $time[1]; ?></br><?php echo $time[0]; ?>  <?php echo $month_arr[@$around_date[1]]?> <?php echo $around_date[0]; ?></font>
            <?php } ?>
            </td>
            <td align="center">
            	<?php if($member['mem_id'] != $all_session['login'][0]['mem_id']) { ?>
                <button class="btn btn-primary " data-toggle="modal" data-target="#edit<?php echo $member['mem_id']; ?>"><span class="glyphicon glyphicon-edit"></span>&nbsp;Grant</button>
         	
              
                <button class="btn btn-danger" data-toggle="modal" data-target="#delete<?php echo $member['mem_id']; ?>" style="height:34px;"><span class="glyphicon glyphicon-remove"></span></button>
               			<?php } ?>
            </td>
          </tr>
          <?php $i++; } ?>
        </table>
      </div>
      <!-- <div class="table-responsive"> --> 
      
    </div>
    <!-- <div class="page-content inset"> --> 
    
  </div>
  <!--  <div id="page-content-wrapper"> --> 
  
</div>
<!-- <div id="wrapper"> -->

<?php $j=1; ?>
<?php foreach($edit as $edit) { ?>

<!-- edit -->

<div class="modal fade" id="edit<?php echo $edit['mem_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel"><strong><?php echo $edit['mem_name']; ?></strong> (
          <?php if($edit['mem_type'] == 0){ echo "member"; } else if ($edit['mem_type'] == 1) { echo "Moderator"; } else if($edit['mem_type']== 2) { echo "Administrator"; } ?>
          ) <a href ="<?php echo base_url();?>index.php/pmember/profile/<?php echo $edit['mem_id'];?>">
          <button type="button" class="btn btn-info" style="width:32px; height:20px; padding:0px;">Info</button>
          </a> </h4>
      </div>
      <div class="modal-body">
      <?php echo form_open('pmember/change_role');?>
      <?php 
					$CI =& get_instance();
					$CI->load->library('convert_role');
					$role = $CI->convert_role->index($edit['mem_type']);
	  ?>
        <table width="100%">
          <tr  height="25em" >
            <td width="4%"></td>
            <td width="20%">Role</td>
            <td width="4%">:</td>
            <td width="72%">            	
            	<select class="form-control" style="width:12em;" name="mem_type">
            	<option value="<?php echo $edit['mem_type'];?>">-- <?php echo $role; ?> --</option>
                <option value="2">Administrator</option>
                <option value="1">Modarator</option>
                <option value="0">Member</option>
                <option value="3">Ban</option>
              </select>
              <input type="hidden" name="mem_id" value="<?php echo $edit['mem_id'];?>" >
              <input type="hidden" name="mem_name" value="<?php echo $edit['mem_name'];?>" >
            </td>
          </tr>
          <tr height="25em" >
            <td></td>
            <td>Start</td>
            <td>:</td>
            <td><input type="text" id="start_<?php echo $edit['mem_id'];?>" data-format="YYYY-MM-DD HH:mm" data-template="D MMM YYYY        HH : mm" name="grant_start_<?php echo $edit['mem_id'];?>" value="<?php echo date("Y-m-d H:i");?>" required/></td>
          </tr>
          <tr height="25em" >
            <td></td>
            <td>End</td>
            <td>:</td>
            <td><input type="text" id="end_<?php echo $edit['mem_id'];?>" data-format="YYYY-MM-DD HH:mm" data-template="D MMM YYYY        HH : mm" name="grant_end_<?php echo $edit['mem_id'];?>" value="<?php echo date("Y-m-d H:i", mktime(date("H"), date("i")+0, date("s")+0, date("m")+0  , date("d")+3, date("Y")+0));?>" required /></td>
          </tr>
          <tr>
            <td colspan="4" align="right" style="padding-top:0.65em"><button type="submit" class="btn btn-warning">Save</button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button></td>
        </table>
        <?php echo form_close();?>
      </div>
    </div>
  </div>
</div>
<!-- edit -->

<script id="js-date">
	$(function(){
		$('#start_<?php echo $edit['mem_id'];?>').combodate();
		$('#end_<?php echo $edit['mem_id'];?>').combodate(); 
	});
</script>

<!-- Delete-->
<div class="modal fade" id="delete<?php echo $edit['mem_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Delete</h4>
      </div>
      <div class="modal-body">
       <?php echo form_open('pmember/delete_member');?>
        <table width="100%">
          <tr>
            <td  height="35em" style="vertical-align:top;">Are you sure you want to delete this?</td>
          </tr>
          <tr>
            <td align="right" ><button type="submit" class="btn btn-danger">Delete</button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Cancle</button>
              <input type="hidden" name="mem_id" value="<?php echo $edit['mem_id']; ?>">
              <input type="hidden" name="mem_name" value="<?php echo $edit['mem_name'];?>">
            </td>
          <tr>
        </table>
        <?php echo form_close();?>
      </div>
    </div>
  </div>
</div>
<!-- Delete--> 
<?php $j++; } ?>





<!-- Custom JavaScript for the Menu Toggle --> 
<script>
    $("#menu-toggle").click(function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("active");
    });
</script> 

<!-- checkbox --> 
<script>
$('#select-all').click(function(event) {   
    if(this.checked) {
        // Iterate each checkbox
        $(':checkbox').each(function() {
            this.checked = true;                        
        });
    }else{
		$(':checkbox').each(function() {
			this.checked = false;
		});
	}
});
</script>
</body>
</html>